//
//  TranstionNetWork.m
//  Shengzhuli
//
//  Created by 卡忙科技 on 16/8/23.
//  Copyright © 2016年 kamangkeji. All rights reserved.
//

#import "TranstionNetWork.h"
#import "GFXNetworkHandle.h"
#import "TranstionModel.h"

NSString * const TranstionListsUrl = @"product/futures/list";//期货列表
NSString * const SecondsListsUrl = @"product/second/market/list";//二级列表
NSString * const TranstionBuyUrl = @"auth/order/buy/create";//期货购买
NSString * const TranstionBuyFirstUrl = @"auth/product/is/first/buy";//期货第一次购买
NSString * const FeeWineBuyUrl = @"auth/free/product/buy";//免费喝红酒购买
NSString * const RuleUrl = @"agreement/activity";//活动规则


@implementation TranstionNetWork

+ (void)getTranstionListWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *lists))response
{
    [[GFXNetworkHandle shareHandle]post:TranstionListsUrl params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *lists = [NSMutableArray array];
            for (NSDictionary *dict in json[@"result"]) {
                TranstionModel *model = [TranstionModel objectWithDict:dict];
                [lists addObject:model];
            }
            response(YES,json[@"message"],lists);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}
+ (void)getSecondsWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *lists))response
{
    [[GFXNetworkHandle shareHandle]post:SecondsListsUrl params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *lists = [NSMutableArray array];
            for (NSDictionary *dict in json[@"result"]) {
                TranstionModel *model = [TranstionModel objectWithDict:dict];
                [lists addObject:model];
            }
            response(YES,json[@"message"],lists);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)transtionBuyWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,SingleCreateModel *model))response
{
    [[GFXNetworkHandle shareHandle]post:TranstionBuyUrl params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            SingleCreateModel *model = [SingleCreateModel objectWithDict:json[@"result"]];
            response(YES,json[@"message"],model);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)checkIsfirstBuyFuturesWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,BOOL isFirst))response
{
    [[GFXNetworkHandle shareHandle]post:TranstionBuyFirstUrl params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:FirstBuyStatus]) {
            response(YES,json[@"message"],YES);
        }else if ([json[@"status"] isEqualToString:SuccessStatus]){
            response(YES,json[@"message"],NO);
        }else{
            response(NO,json[@"message"],NO);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,NO);
    }];
}

+ (void)feeWineBuyWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,PaySingleModel *model))response
{
    [[GFXNetworkHandle shareHandle]post:FeeWineBuyUrl params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]||[json[@"status"] isEqualToString:FirstBuyStatus]) {
            PaySingleModel *model = [PaySingleModel objectWithDict:json[@"result"]];
            if ([json[@"status"] isEqualToString:FirstBuyStatus]) {
                model.isFirstBuy = YES;
            }
            response(YES,json[@"message"],model);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)getRuleWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSString *rule))response
{
    [[GFXNetworkHandle shareHandle]post:RuleUrl params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]||[json[@"status"] isEqualToString:FirstBuyStatus]) {
            response(YES,json[@"message"],json[@"result"]);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

@end
